﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using CNdotnet.Ezsocio.Core.DataEntity;

namespace CNdotnet.Ezsocio.DataEntities
{
    [Table(Name = "dbo.Resume")]
    public class Resume : Entity
    {
        #region Private Fields

        private int _Id;

        private int _userId;

        private short _type;

        private DateTime _startDate;

        private DateTime _endDate;

        private string _place;

        private string _department;

        private string _position;

        private EntityRef<User> _user;

        #endregion

        #region Constructor

        public Resume()
        {
            this._user = default(EntityRef<User>);
        }

        #endregion

        #region Public Properties

        [Column(Name = "ID", Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ID
        {
            get
            {
                return this._Id;
            }
            set
            {
                if (this._Id != value)
                {
                    this.SendPropertyChanging("ID");
                    this._Id = value;
                    this.SendPropertyChanged("ID", value);
                }
            }
        }

        [Column(Name = "UserId", Storage = "_userId", DbType = "Int NOT NULL")]
        public int UserId
        {
            get
            {
                return this._userId;
            }
            set
            {
                if (this._userId != value)
                {
                    if (this._user.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }

                    this.SendPropertyChanging("UserId");
                    this._userId = value;
                    this.SendPropertyChanged("UserId", value);
                }
            }
        }

        [Column(Name = "Type", Storage = "_type", DbType = "TinyInt NOT NULL")]
        public short Type
        {
            get
            {
                return this._type;
            }
            set
            {
                if (this._type != value)
                {
                    this.SendPropertyChanging("Type");
                    this._type = value;
                    this.SendPropertyChanged("Type", value);
                }
            }
        }

        [Column(Name = "StartDate", Storage = "_startDate", DbType = "DateTime NOT NULL")]
        public DateTime StartDate
        {
            get
            {
                return this._startDate;
            }
            set
            {
                if (this._startDate != value)
                {
                    this.SendPropertyChanging("StartDate");
                    this._startDate = value;
                    this.SendPropertyChanged("StartDate", value);
                }
            }
        }

        [Column(Name = "EndDate", Storage = "_endDate", DbType = "DateTime NOT NULL")]
        public DateTime EndDate
        {
            get
            {
                return this._endDate;
            }
            set
            {
                if (this._endDate != value)
                {
                    this.SendPropertyChanging("EndDate");
                    this._endDate = value;
                    this.SendPropertyChanged("EndDate", value);
                }
            }
        }

        [Column(Name = "Place", Storage = "_place", DbType = "VarChar(128) NOT NULL", CanBeNull = false)]
        public string Place
        {
            get
            {
                return this._place;
            }
            set
            {
                if (this._place != value)
                {
                    this.SendPropertyChanging("Place");
                    this._place = value;
                    this.SendPropertyChanged("Place", value);
                }
            }
        }

        [Column(Name = "Department", Storage = "_department", DbType = "VarChar(128) NOT NULL", CanBeNull = false)]
        public string Department
        {
            get
            {
                return this._department;
            }
            set
            {
                if (this._department != value)
                {
                    this.SendPropertyChanging("Department");
                    this._department = value;
                    this.SendPropertyChanged("Department", value);
                }
            }
        }

        [Column(Name = "Position", Storage = "_position", DbType = "VarChar(128) NOT NULL", CanBeNull = false)]
        public string Position
        {
            get
            {
                return this._position;
            }
            set
            {
                if (this._position != value)
                {
                    this.SendPropertyChanging("Position");
                    this._position = value;
                    this.SendPropertyChanged("Position", value);
                }
            }
        }

        [Association(Name = "User_Resume", Storage = "_user", ThisKey = "UserId", IsForeignKey = true)]
        public User User
        {
            get
            {
                return this._user.Entity;
            }
            set
            {
                User previousValue = this._user.Entity;
                if (((previousValue != value)
                            || (this._user.HasLoadedOrAssignedValue == false)))
                {
                    if ((previousValue != null))
                    {
                        this._user.Entity = null;
                        previousValue.Resumes.Remove(this);
                    }
                    this._user.Entity = value;
                    if ((value != null))
                    {
                        value.Resumes.Add(this);
                        this._userId = value.ID;
                    }
                    else
                    {
                        this._userId = default(int);
                    }
                }
            }
        }

        #endregion
    }
}
